#include "StdAfx.h"
#include "Exception.h"

#include <sstream>

Exception::Exception( int code /*= 0*/, const std::string& message /*= ""*/ )
	: std::exception(), m_code(code), m_message(message)
{
}


Exception::Exception( const Exception& rhs ) : 
	std::exception(rhs), m_message(rhs.m_message), m_code(rhs.m_code)
{
}

Exception::~Exception()
{
}

Exception& Exception::operator=( const Exception& rhs )
{
	if (&rhs != this)
	{
		m_message = rhs.m_message;
		m_code = rhs.m_code;
	}
	return *this;
}

const char* Exception::what() const throw()
{
	return GetDisplayText().c_str();
}

const std::string& Exception::GetMessage() const
{
	return this->m_message;
}

int Exception::GetCode() const
{
	return this->m_code;
}

std::string Exception::GetDisplayText() const
{
	std::ostringstream oss;
	oss << "code: " << m_code << ", message:" << m_message;
	return oss.str();
}

template <typename E>
void ThrowException( const std::string& message, const std::string& description )
{
	std::ostringstream oss;
	oss << message << ":" << description;
	E e(0, oss.str());
	throw e;
}
